﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows;
using System.Windows.Input;

using ASApplication;

using ASWPF;

using FXnaMet;


namespace ASPresentation
{
   public static  class ASCoreCommandsBinder
    {

        static RoutedCommand editPsLayer=new RoutedCommand ();

        public static RoutedCommand EditPsLayer
        {
            get { return ASCoreCommandsBinder.editPsLayer; }
           
        }


        static RoutedCommand editSurfData = new RoutedCommand();

        public static RoutedCommand EditSurfData
        {
            get { return ASCoreCommandsBinder.editSurfData; }
            
        }


        static RoutedCommand editUpperAir = new RoutedCommand();

        public static RoutedCommand EditUpperAir
        {
            get { return ASCoreCommandsBinder.editUpperAir; }
            

        }




       
           /// <summary>
        /// 将命令绑定到窗体
        /// </summary>
        /// <param name="window"></param>
       public static void BindCommandsToWindow(Window window)
       {



           CommandBinding cbEditPs = new CommandBinding();
           cbEditPs.Command = ASCoreCommandsBinder.editPsLayer;
           cbEditPs.CanExecute += new CanExecuteRoutedEventHandler(cbEditPs_CanExecute);
           cbEditPs.Executed += new ExecutedRoutedEventHandler(cbEditPs_Executed);

           window.CommandBindings.Add(cbEditPs);


           CommandBinding cbEditSurf = new CommandBinding();
           cbEditSurf.Command = ASCoreCommandsBinder.editSurfData;
           cbEditSurf.CanExecute += new CanExecuteRoutedEventHandler(cbEditSurf_CanExecute);
           cbEditSurf.Executed += new ExecutedRoutedEventHandler(cbEditSurf_Executed);

           window.CommandBindings.Add(cbEditSurf);


           CommandBinding cbEditUpperAir = new CommandBinding();
           cbEditUpperAir.Command = ASCoreCommandsBinder.editUpperAir;
           cbEditUpperAir.CanExecute += new CanExecuteRoutedEventHandler(cbEditUpperAir_CanExecute);
           cbEditUpperAir.Executed += new ExecutedRoutedEventHandler(cbEditUpperAir_Executed);

           window.CommandBindings.Add(cbEditUpperAir);






       }

       static void cbEditUpperAir_Executed(object sender, ExecutedRoutedEventArgs e)
       {

           MetUOQAFile u = new MetUOQAFile();
           u.ReadFile(@"c:\test\u.oqa");

           ProjectService.CurrentService.Project.ASData.UpperAirFile = u;

           MessageBox.Show("ceshi upperai ok!");


       }

       static void cbEditUpperAir_CanExecute(object sender, CanExecuteRoutedEventArgs e)
       {
           if (!ProjectService.CurrentService.BNullProj)
           {
               e.CanExecute = true;
               e.Handled = true;

           }

       }

       static void cbEditSurf_Executed(object sender, ExecutedRoutedEventArgs e)
       {

           MetOQAFile file = new MetOQAFile();

           file.ReadFile(@"c:\test\s.oqa");


           ProjectService.CurrentService.Project.ASData.SurfFile = file;

           MessageBox.Show("ceshi surf ok!");




       }

       static void cbEditSurf_CanExecute(object sender, CanExecuteRoutedEventArgs e)
       {
           if (!ProjectService.CurrentService.BNullProj)
           {
               e.CanExecute = true;
               e.Handled = true;

           }


       }

       static void cbEditPs_Executed(object sender, ExecutedRoutedEventArgs e)
       {
           

           winPsList win = new winPsList(ProjectService.CurrentService.Project.ASData.PtLayer);

           if (win.ShowDialog()==true)
           {

               GisService.CurrentService.CurrentMap.GeoMapFrame.SuspendEvents();

               ProjectService.CurrentService.Project.ASData.PtLayer.ResetShapes(win.Shapes);

               GisService.CurrentService.CurrentMap.GeoMapFrame.ResumeEvents();

               
           }
          
       }

       static void cbEditPs_CanExecute(object sender, CanExecuteRoutedEventArgs e)
       {
           if (!ProjectService.CurrentService.BNullProj)
           {
               e.CanExecute = true;
               e.Handled = true;

           }
           
       }



    }
}
